package com.android.allwinner.newaw360;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.VideoView;

import com.android.allwinner.newaw360.utils.StringUtils;

/**
 * Created by Administrator on 2017/8/1.
 */

public class PlayActivity extends AppCompatActivity{
    public static final String KEY_PATH = "path";
    private String mPathString;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play);
        initView();
    }
    private void initView() {
        Intent intent = getIntent();
        mPathString = intent.getStringExtra(KEY_PATH);
        if (StringUtils.isEmpty(mPathString)) {
            finish();
            return;
        }
        VideoView videoView = (VideoView) findViewById(R.id.videoView);
        Log.i("PlayActivity","the videopath is "+mPathString);
        videoView.setVideoURI(Uri.parse(mPathString));
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                finish();
            }
        });

        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.FILL_PARENT,
                RelativeLayout.LayoutParams.FILL_PARENT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        videoView.setLayoutParams(layoutParams);
        videoView.setMediaController(new MediaController(this));

        videoView.requestFocus();
        videoView.start();
    }
}
